//
//  HPSearchViewCell.m
//  HappyPenguin
//
//  Created by zhuangyihang on 1/31/16.
//  Copyright © 2016 zhuangyihang. All rights reserved.
//

#import "HPSearchViewCell.h"
#import "UIConstants.h"
#import "NSString+Common.h"

static NSInteger kDescFontSize = 14;
static NSInteger kNameFontSize = 16;

@implementation HPSearchViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.portraitView = [UIImageView new];
        [self.contentView addSubview:self.portraitView];
        [self.portraitView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@50);
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(@5);
        }];
        self.portraitView.image = [UIImage imageNamed:@"DefaultPortrait"];
        self.portraitView.contentMode = UIViewContentModeScaleAspectFill;
        self.portraitView.clipsToBounds = YES;
        
        self.nameLabel = [UILabel new];
        [self.contentView addSubview:self.nameLabel];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@5);
            make.left.equalTo(self.portraitView.mas_right).offset(5);
        }];
        self.nameLabel.font = [UIConstants getFont:kNameFontSize];
        self.nameLabel.textColor = [UIConstants getAppColor];
        
        self.descLabel = [UILabel new];
        [self.contentView addSubview:self.descLabel];
        [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
            make.left.equalTo(self.nameLabel);
        }];
        self.descLabel.font = [UIConstants getFont:kDescFontSize];
        self.descLabel.textColor = [UIColor colorWithRGB:0x808080];
        self.descLabel.numberOfLines = 0;
    }
    return self;
}

+ (CGFloat)getCellHeight:(NSString *)desc{
    
    CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
    CGFloat height = 5;
    
    height += [@"" getHeightWithWidth:CGFLOAT_MAX withFont:[UIConstants getFont:kNameFontSize]];
    height += 5;
    
    CGFloat width = screenWidth - 50 - 5 - 5 - 20;
    height += [desc getHeightWithWidth:width withFont:[UIConstants getFont:kDescFontSize]];
    
    height += 5;
    
    return height;
}

@end
